#!/bin/bash
#
#
#    Run WARP3D on OS X -- OpenMP only + MKL sparse solver
#    =====================================================
#
#    usage: warp3d_mac   ( number of threads )   ( < input ) ( > output )
#
#           ( ) -- optional
#
#
if [ $# = "0" ]; then
   echo ">> Usage:"; echo " "
   echo " warp3d_mac ( <parms> )     ( < input ) ( > output )"; echo " "
   echo " <parms>: <no. of threads>  "
   echo "  ( )  implies optional"
   echo " "
   exit 1
fi
#
echo " "
echo ">> Running WARP3D on Mac OS X ..."
echo "   OpenMP + threaded MKL direct/iterative sparse solver "
#
if [ -z "$WARP3D_HOME" ]; then
   printf "[ERROR]\n"
   printf "... An environment variable WARP3D_HOME is not set.\n"
   printf "Quitting...\n"
   exit 1
fi
#
#           set executable file name for OpenMP + MKL sparse solver
#           version of warp3d
#
warp3d_exe="$WARP3D_HOME/run_mac_os_x/warp3d.omp"
#
#           set the number of threads for WARP3D execution and
#           for use by the MKL sparse direct/iterative solver. Here we just
#           assign the same number of threads for both.
#           default to 1 thread if user does nothing.
#
export OMP_NUM_THREADS=1
if [ $# = "1"  ]; then
    export OMP_NUM_THREADS=$1
fi
export MKL_NUM_THREADS=$OMP_NUM_THREADS
#
echo ">> Number of threads for parallel execution: " $OMP_NUM_THREADS
echo " "
#
touch core &> /dev/null
chmod ugo-rwx core
#
ulimit -s 32768
$warp3d_exe
#
/bin/rm -f core
exit



